package com.manor.dynamic.adapter;

import android.view.View;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.manor.dynamic.R;
import com.manor.dynamic.upload.UploadBean;

import java.util.List;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

public class PublishImgAdapter extends BaseQuickAdapter<UploadBean, BaseViewHolder> {
    public PublishImgAdapter(int layoutResId, @Nullable List<UploadBean> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(@NonNull BaseViewHolder helper, UploadBean item) {
        ImageView ivImg = helper.getView(R.id.item_img);
        ImageView btn_del_img = helper.getView(R.id.btn_del_img);

        if(null==item.getOriginFile()){
         //   Glide.with(mContext).load(item.getOriginFile().getAbsolutePath()).into(ivImg);
            ivImg.setImageResource(R.mipmap.addphoto);
            btn_del_img.setVisibility(View.GONE);
        }else {
            RequestOptions op = new RequestOptions();
            op.transform(new CenterCrop(),new RoundedCorners(16));

            btn_del_img.setVisibility(View.VISIBLE);
            Glide.with(getContext()).load(item.getOriginFile().getAbsolutePath())
                    .apply(op)
                    .apply(RequestOptions.diskCacheStrategyOf(DiskCacheStrategy.ALL))
                    .into(ivImg);
         //   Glide.with(getContext()).load(item.getOriginFile().getAbsolutePath()).into(ivImg);

        }

        addChildClickViewIds(R.id.btn_del_img);
    }
}
